package com.ateam.dao.impl;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;

import com.ateam.dao.MissionsDao;
import com.ateam.pojo.Missions;

/** 
* @author WuYuan
* 
*/
public class MissionsDaoImpl implements MissionsDao {
	private SqlSessionTemplate sqlSessionTemplate;
	
	public SqlSessionTemplate getSqlSessionTemplate() {
		return sqlSessionTemplate;
	}

	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlSessionTemplate = sqlSessionTemplate;
	}
	@Override
	public int addMission(Missions mission) throws Exception {
		return sqlSessionTemplate.insert("addMission", mission);
	}

	@Override
	public int addMissionleader(int userid, int missionid) throws Exception {
		Object [] objects =new Object[]{userid,missionid};
		return sqlSessionTemplate.insert("addMissionleader", objects);
	}

	@Override
	public int addMissionmember(int userid, int missionid) throws Exception {
		System.out.println("正在插入数据user_mission"+userid+"  对应的missionid是"+missionid);
		Object [] objects =new Object[]{userid,missionid};
		return sqlSessionTemplate.insert("addMissionmember", objects);
	}

	@Override
	public int deleteMissionmember(int userid, int missionid) throws Exception {
		Object [] objects =new Object[]{userid,missionid};
		return sqlSessionTemplate.delete("deleteMissionmember", objects);
	}

	@Override
	public List<Missions> getMissionsByUserid(int userid) throws Exception {
		return sqlSessionTemplate.selectList("getMissionsByUserid", userid);
	}

	@Override
	public int updateMissionComplete(int userid,int missionid) throws Exception {
		Object [] objects =new Object[]{userid,missionid};
		return sqlSessionTemplate.update("updateMissionComplete", objects);
	}

	@Override
	public int countMissionsHaveDone(int companyid) throws Exception {
		return sqlSessionTemplate.selectOne("countMissionsHaveDone",companyid);
	}

	@Override
	public int countMissionsHaventDone(int companyid) throws Exception {
		return sqlSessionTemplate.selectOne("countMissionsHaventDone",companyid);
	}

	@Override
	public List<Missions> getMissionsDoneByUserid(int userid) throws Exception {
		return sqlSessionTemplate.selectList("getMissionsDoneByUserid", userid);
	}

	@Override
	public Missions getMissionByMissionid(int missionid) throws Exception {
		return sqlSessionTemplate.selectOne("getMissionByMissionid", missionid);
	}
}
